#include "csgtransformation.h"

CSGTransformation::CSGTransformation(Axis axis , double dAngle){
    //Constructor for rotations about one axis.
    double dAngleRads = dAngle * PI / 180.0;
    double dAngleCos = cos(dAngleRads);
    double dAngleSin = sin(dAngleRads);

    switch(axis){
        case X_AXIS:{
            transformation = Transformation(dAngleCos  , 0.0 , dAngleSin , 0.0 ,
                                            0.0        , 1.0 , 0.0       , 0.0 ,
                                            -dAngleSin , 0.0 , dAngleCos , 0.0);
            break;
        }
        case Y_AXIS:{
            transformation = Transformation(1.0 , 0.0        , 0.0       , 0.0 ,
                                            0.0 , dAngleCos  , dAngleSin , 0.0 ,
                                            0.0 , -dAngleSin , dAngleCos , 0.0);
            break;
        }
        case Z_AXIS:{
            transformation = Transformation(dAngleCos , -dAngleSin , 0.0 , 0.0 ,
                                            dAngleSin ,  dAngleCos , 0.0 , 0.0 ,
                                            0.0       ,  0.0       , 1.0 , 0.0);
            break;
        }
        default: cout << "Error with transformation" << endl; break;
    }
    transformation = transformation.inverse();
}

CSGTransformation::CSGTransformation(double dScaleFactor){
    //Contruction for scaling.
    transformation = Transformation(CGAL::SCALING , dScaleFactor);
    transformation = transformation.inverse();
}

CSGTransformation::CSGTransformation(Vector translation){
    //Constructor for translation.
    transformation = Transformation(CGAL::TRANSLATION , translation);
    transformation = transformation.inverse();
}

XYZ CSGTransformation::transform(XYZ p){
    Point pTemp = Point(p.x , p.y , p.z);
    pTemp = transformation.transform(pTemp);
    XYZ pTransformed(pTemp.x() , pTemp.y() , p.z = pTemp.z());

    return pTransformed;
}
